package com.example.user_service.user_contorller;


import com.example.user_service.otherservice.Otherservice;
import com.example.user_service.return_data.Mall_Data;
import com.example.user_service.service.Lservice;
import com.example.user_service.vo.Administrator;
import com.example.user_service.vo.Memu;
import com.example.user_service.vo.Role;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.spring.web.json.Json;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author XiaoLiu
 * @date 2021-12-01 16:26
 **/
@RestController("/LhjController")
@Api
@CrossOrigin
public class LController {
    @Autowired
    Otherservice otherservice;//远程调用

    @Autowired
    Lservice lservice;


    /* 利用openFeign远程调用菜单服务查询用户个人中心菜单
     * @author Liu
     * @date 2021/12/13 8:34
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/MenuSelect")
    @CrossOrigin
    @HystrixCommand(fallbackMethod = "Demotion")
    @ApiOperation("查询个人中心菜单")
    public Mall_Data MenuSelect() {
         return otherservice.get(20);
    }

    /* 用于后台管理员添加修改时选择的角色类型而用
     * @author Liu
     * @date 2021/12/14 10:26
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/SelectRole")
    @CrossOrigin
    /*@HystrixCommand(fallbackMethod = "Demotion")*/
    @ApiOperation("查询后台管理员")
    public Mall_Data RoleSelect()
    {
        return otherservice.SelectRole("管理员");
    }

    /* 查询管理员表
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/AdministratorSelect")
    @ApiOperation("查询管理员表")
    public Mall_Data AdministratorSelect(@ApiParam("开始日")@RequestParam(value = "start",required = false) String createdatestr
    ,                                    @ApiParam("截止日")@RequestParam(value = "end",required = false) String enddatestr
    ,                                    @ApiParam("管理员账号")@RequestParam(value = "account",required = false) String account)
    {
        Mall_Data mall_data = new Mall_Data();
        mall_data.setcode(200);
        mall_data.setdata(lservice.AdministratorSelect(createdatestr,enddatestr,account));
        return mall_data;
    }

    /* 校验管理员账号是否存在
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/check_Administrator")
    @ApiOperation("校验管理员账号是否存在")
    public Mall_Data check_Administrator(@ApiParam("管理员对象")@RequestBody Administrator administrator)
    {
        Mall_Data mall_data = new Mall_Data();
        if (lservice.check_Administrator(administrator)){
            //设置状态码
            mall_data.setcode(200);
            //设置error信息
            mall_data.seterror("not error");
            //设置数据信息
            mall_data.setdata("账号没重复");
        }else {
            //设置状态码
            mall_data.setcode(520);
            //设置error信息
            mall_data.seterror("账号重复");
        }
        return mall_data;
    }


    /* 创建管理人员
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/create_Administrator")
    @ApiOperation("创建管理人员")
    public Mall_Data create_Administrator(@ApiParam("管理员对象")@RequestBody Administrator administrator)
    {
        Mall_Data mall_data = new Mall_Data();
        if (lservice.create_Administrator(administrator)==1){
            //设置状态码
            mall_data.setcode(200);
            //设置error信息
            mall_data.seterror("not error");
            //设置数据信息
            mall_data.setdata("创建成功");
        }else {
            //设置状态码
            mall_data.setcode(520);
            //设置error信息
            mall_data.seterror("创建失败");
        }
        return mall_data;
    }

    /* 删除管理人员
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/delete_Administrator")
    @ApiOperation("删除管理人员")
    public Mall_Data delete_Administrator(@ApiParam("管理员对象")@RequestBody Administrator administrator)
    {
        Mall_Data mall_data = new Mall_Data();
        mall_data.setdata( lservice.delete_Administrator(administrator));
        return mall_data;
    }

    /* 修改管理人员
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/update_Administrator")
    @ApiOperation("修改管理人员")
    public Mall_Data update_Administrator(@ApiParam("管理员对象")@RequestBody Administrator administrator)
    {
        Mall_Data mall_data = new Mall_Data();
        mall_data.setdata( lservice.update_Administrator(administrator));
        return mall_data;
    }

    /* 修改管理人员状态
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/update_Administrator_state")
    @ApiOperation("修改管理人员状态")
    public Mall_Data update_Administrator_state(@ApiParam("管理员对象")@RequestBody Administrator administrator)
    {
        Mall_Data mall_data = new Mall_Data();
        mall_data.setdata( lservice.update_Administrator_state(administrator));
        return mall_data;
    }

    /* 查询用户积分
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/select_member_existing_integral")
    @ApiOperation("查询用户积分")
    public Mall_Data select_member_existing_integral(@ApiParam("用户id")@RequestParam("userid") int userid)
    {
        return new Mall_Data().setdata(lservice.select_member_existing_integral(userid).getMember_existing_integral());
    }

    /* 修改用户积分
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/update_member_existing_integral")
    @ApiOperation("修改用户积分")
    public Mall_Data update_member_existing_integral(@ApiParam("用户id")@RequestParam("userid") int userid,
                                                     @ApiParam("积分格式例如-500或+500")@RequestParam(value = "str",required = false)String str)
    {

        return new Mall_Data().setdata(lservice.update_member_existing_integral(userid,str));
    }

    /* 查询我的足迹
     * @author Liu
     * @date 2021/12/14 14:52
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/select_my_tracks")
    @ApiOperation("查询我的足迹")
    public Mall_Data select_my_tracks(@ApiParam("用户id")@RequestParam("userid") int userid)
    {


        return new Mall_Data().setdata(lservice.select_my_tracks(userid));
    }

    /* 删除我的足迹
     * @author Liu
     * @date 2021/12/17 14:39
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/delete_my_tracks")
    @ApiOperation("删除我的足迹")
    public Mall_Data delete_my_tracks(@ApiParam("足迹id")@RequestParam("tracks_id") int tracks_id)
    {
        return new Mall_Data().setdata(lservice.delete_my_tracks(tracks_id));
    }


    /* 新增我的足迹
     * @author Liu
     * @date 2021/12/17 14:39
     * @param null
     * @return
     * @throws
     * @since
     */
    @RequestMapping("/insert_my_tracks")
    @ApiOperation("新增我的足迹")
    public Mall_Data insert_my_tracks(@ApiParam("用户id")@RequestParam("user_id") int user_id,
                                      @ApiParam("商品id")@RequestParam("footprint_id") int footprint_id)
    {
        return new Mall_Data().setdata(lservice.insert_my_tracks(user_id,footprint_id));
    }

    /* 熔断处理降级
     * @author Liu
     * @date 2021/12/9 14:20
     * @param null
     * @return
     * @throws
     * @since
     */
    public Mall_Data Demotion() {
        System.out.println("你报错了.....看看隔壁菜单挂了没.......没有就是你的方法有问题........");
        return null;
    }


}
